<?php
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

$db = NEW myDBS();

$sql = "SELECT approved_date, receiver, pet_id, tax1, amount "
        . " FROM tbl_pet "
        . " WHERE approved_status = 'อนุมัติ' "
        . " AND tax1 <> 0"
        . " UNION ALL"
        . " SELECT approved_date, company_name AS receiver, p_id as pet_id, WithholdingTax AS tax1, inpValues AS amount "
        . " FROM tbl_petition "
        . " WHERE approved_status = 'อนุมัติ' "
        . " AND WithholdingTax <> 0"
        . " UNION "
        . " SELECT approved_date, card_id AS receiver, pet_id, tax1, tax1 AS amount "
        . " FROM tbl_salary, tbl_init "
        . " WHERE tbl_salary.id = tbl_init.card_id"
        . " AND approved_status = 'อนุมัติ' "
        . " AND tax1 <> 0";

//echo $sql;

$result = $db->runSQL($sql);
?>

<script type="text/javascript">
    $(document).ready(function() {
        $("#example").dataTable();

    });
</script>

<table class="table table-hover table-bordered" id='example'>
    <thead>
    <th>#</th>
    <th>วันที่</th>
    <th>ผู้ถูกหักภาษี</th>
    <th>เลขที่ฎีกา</th>
    <th>ภาษีหัก ณ ที่จ่าย</th>
</thead>
<tbody>
    <?php
    $i = 1;
    while ($rows = $db->fetch_object($result)) {
        ?>
        <tr>
            <td><?php echo $i; ?></td>
            <td><?php echo $rows->approved_date; ?></td>
            <td>
                <?php 
                if (is_numeric($rows->receiver)) {
                    echo get_name_person($rows->receiver);
                } else {
                    echo $rows->receiver;
                }
                
                ?>
            </td>
            <td><?php echo $rows->pet_id; ?></td>
            <td>
                <p class="text-right">
                    <?php
                    if ($rows->amount == $rows->tax1) {
                        echo $rows->tax1;
                    } else {
                        echo number_format($rows->amount * $rows->tax1 / 100, 2);
                    }
                    
                    ?>
                </p>
            </td>
        </tr>
        <?php
        $i++;
    }
    ?>
</tbody>
</table>
<p class="text-center"><a class="btn btn-success" href="rpt_tax1_print.php" target="_blank"><i class="icon-print icon-white"></i> พิมพ์รายงาน</a></p>
